<template>
  <div class="login-card">
    <h1 class="title">便利店仓储管理系统</h1>
    <div class="tabs">
      <el-tabs type="border-card" stretch v-model="activeName">
        <el-tab-pane name="account">
          <template #label>
            <div class="label">
              <span
                ><el-icon><UserFilled /></el-icon
              ></span>
              <span class="text">账号登录</span>
            </div>
          </template>
          <Account ref="accountRef" />
        </el-tab-pane>
        <el-tab-pane name="phone">
          <template #label>
            <div class="label">
              <span
                ><el-icon><Iphone /></el-icon
              ></span>
              <span class="text">手机登录</span>
            </div>
          </template>
          <Phone />
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="contorl-account">
      <el-checkbox v-model="keepPassword" label="记住密码" size="large" />
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button class="login-btn" type="primary" size="large" @click="handleLoginAction"
      >登录</el-button
    >
  </div>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue'
import Account from './Account.vue'
import Phone from './Phone.vue'
import { localCache } from '@/utils/cache'

const keepPassword = ref<boolean>(localCache.getCache('keepPassword') ?? false)

watch(keepPassword, (newValue) => {
  localCache.removeCache('keepPassword')
  localCache.setCache('keepPassword', newValue)
})

const activeName = ref('account')
const accountRef = ref<InstanceType<typeof Account>>()
const handleLoginAction = () => {
  if (activeName.value === 'account') {
    accountRef.value?.LoginAction(keepPassword.value)
  } else {
    console.log(activeName.value)
  }
}
</script>

<style scoped>
.login-card {
  width: 330px;
  margin-bottom: 150px;

  .title {
    text-align: center;
    margin-bottom: 15px;
  }
  .label {
    display: flex;
    justify-content: center;
  }
  .text {
    margin-left: 5px;
  }
}
.contorl-account {
  margin-left: 5px;
  display: flex;
  justify-content: space-between;
}
.login-btn {
  margin-top: 10px;
  width: 100%;
}
</style>
